package io.github.uicdb.badskill.api;

import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import io.github.uicdb.badskill.SkillOption;
import io.github.uicdb.badskill.SkillOptionManager;
import lombok.SneakyThrows;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.ModList;

import java.util.Collection;
import java.util.concurrent.CompletableFuture;

public class OptionArgType implements ArgumentType<SkillOption> {
    @SneakyThrows
    @Override
    public SkillOption parse(StringReader reader) {
        var res=ResourceLocation.read(reader);
        return SkillOptionManager.INSTANCE.OPTIONS.get(res);
    }

    @Override
    public <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder) {
        return SharedSuggestionProvider.suggest(SkillOptionManager.INSTANCE.OPTIONS.values().stream().map(s->s.id.toString()), builder);
    }

    @Override
    public Collection<String> getExamples() {
        return ArgumentType.super.getExamples();
    }
    public static OptionArgType option() {
        return new OptionArgType();
    }
    public static SkillOption getOption(CommandContext<CommandSourceStack> context, String key) {
        return context.getArgument(key, SkillOption.class);
    }
}
